package com.mit.wx.interceptor.config;

import com.mit.wx.conf.AuthConfiguration;
import com.mit.wx.interceptor.AccessAuthInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

/**
 * 2018/10/20 Create by 郭文梁
 * InterceptorsConfigurer
 * 配置拦截器
 *
 * @author 郭文梁
 * @date 2018/10/20
 */
@Configuration
public class InterceptorsConfigurer implements WebMvcConfigurer {
    private final AuthConfiguration configuration;

    @Autowired
    public InterceptorsConfigurer(AuthConfiguration configuration) {
        this.configuration = configuration;
    }

    private List<String> buildInterceptorPatterns() {
        List<String> patterns = new ArrayList<>();
        patterns.add("/auto-reply-rule/**");
        patterns.add("/kf/**");
        patterns.add("/material/**");
        patterns.add("/user/**");
        patterns.add("/admin/**");
        return patterns;
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new AccessAuthInterceptor(configuration))
                .addPathPatterns(buildInterceptorPatterns());
    }
}
